package web_k;

import pojo_k.HomeUser;
import service_k.HomeUserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/homeUserLoginServlet")
public class HomeUserLoginServlet extends HttpServlet {
    private HomeUserService service = new HomeUserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收登录信息
        String homeuserName = request.getParameter("homeuserName");
        String homeuserPassword = request.getParameter("homeuserPassword");

        //2.调用service查询
        HomeUser homeUser = service.homeUserSelect(homeuserName, homeuserPassword);

        //获取字符输出流，并设置content type
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();

        //3.判断user是否登陆成功
        if (homeUser != null){
            //登陆成功
            response.sendRedirect("/project1_war/HomeUserAccounting.jsp");
        } else {
            //登陆失败
            writer.write("登陆失败");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
